using System.Collections;
using UnityEngine;

public class WarningSign : MonoBehaviour
{
    public float flashDuration = 2f; // 闪烁的总持续时间
    public float flashInterval = 0.2f; // 闪烁的间隔时间

    private SpriteRenderer spriteRenderer;
    private bool isFlashing = true;

    void Start()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        StartCoroutine(Flash());
    }

    IEnumerator Flash()
    {
        float endTime = Time.time + flashDuration;

        while (Time.time < endTime)
        {
            spriteRenderer.enabled = !spriteRenderer.enabled;
            yield return new WaitForSeconds(flashInterval);
        }

        // 最后确保警告标志可见（或不可见，如果你希望这样）
        spriteRenderer.enabled = false;
        Destroy(gameObject);
    }
}